package com.hm.cms.api;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hm.cms.auto.su.ControllerResult;
import com.hm.cms.auto.su.R;
import com.hm.cms.service.VisitIpStatisticsService;
import com.hm.common.su.bean.ServerResponse;
import com.hm.common.util.RemoteClientUtil;

import io.swagger.annotations.ApiOperation;

/**
 * @author shishun.wang
 * @date 2017年12月28日 上午11:20:02
 * @version 1.0
 * @describe 
 */
@ResponseBody
@RestController
@RequestMapping(R.Restful.API + "/visitIpStatistics")
public class VisitIpStatisticsApi {

	private static final String SWWAGER_TAG = "数据访问统计";
	
	@Autowired
	private VisitIpStatisticsService visitIpStatisticsService;
	
	@RequestMapping(value = "/request", method = RequestMethod.POST)
	@ApiOperation(tags = SWWAGER_TAG, value = "客户端请求统计", httpMethod = "PATCH", notes = "客户端请求统计")
	public ResponseEntity<ServerResponse<Boolean>> requestVisitIpStatistics(HttpServletRequest request) {
		String ip = RemoteClientUtil.getPackHost(request);
		visitIpStatisticsService.saveVisitIpStatistics(ip, request.getParameter("uri"));
		return ControllerResult.success(true);
	}
}
